package com.samuel.algorithm.array;

public class RemoveDuplicates {

    public int removeDuplicates(int[] nums) {
        if (0 == nums.length) {
            return 0;
        }
        int slow = 1, fast = 1;
        while (fast < nums.length) {
            if (nums[fast] != nums[slow - 1]) {
                nums[slow] = nums[fast];
                slow++;
            }
            fast++;
        }
        return slow;
    }

    public int removeDuplicates2(int[] nums) {
        if (0 == nums.length) {
            return 0;
        }
        int slow = 2, fast = 2;
        while (fast < nums.length) {
            if (nums[fast] != nums[slow - 1]) {
                nums[slow] = nums[fast];
                slow++;
            } else if (nums[fast] != nums[slow - 2]){
                nums[slow] = nums[fast];
                slow++;
            }
            fast++;
        }
        return slow;
    }
}
